/**
 * 封装 document.getElementById
 */
function $($id, winHDL) {
	if (typeof(winHDL) === 'undefined') {
		winHDL = window;
	}
	return winHDL.document.getElementById($id);
}

/**
 * 得到 URL 中的界面语言值
 */
function getAddressLang() {
	var addressLang = location.search.match(/lang=(\w+)/);
	addressLang = addressLang ? addressLang[1] : 'zh_cn';
	return addressLang;
}

/**
 * 从 URL 中取得当前的安装步骤
 */
function getCurStep() {
	var curStep = location.search.match(/step=(\w+)/);
	curStep = curStep ? curStep[1] : 'welcome';
	return curStep;
}

/**
 * 调整语言
 */
function setInputCheckedStatus() {
	var targetInput = $("js-" + getAddressLang());
	if (!targetInput) {
		return;
	}
	targetInput.setAttribute('checked', 'checked');
	var langOptions = document.getElementsByName('js-lang');
	for (var i=0; i < langOptions.length; i++) {
		langOptions[i].onclick = function() {
			var selectedLang = this.getAttribute('id').slice(3);
			location.href='./index.php?lang=' + selectedLang + '&step=' + getCurStep();
		};
	}
};
